<div style="padding-top: 15px; padding-bottom: 15px;">
	<div class="container">
		<a routerLink="/learn" class="btn btn-outline-dark" style="margin-top: 5px;">Back</a>
		<h2>Audio</h2>
		<p>nunuStudio uses WebAdio to provide a fully featured audio engine, with support for effects, positional audio, analysis tools etc. To use audio elements the host must support WebAudio since there is no fallback for hosts without this API available.</p>
		<p>More information about the WebAudio API can be found <a href="https://webaudio.github.io/web-audio-api/">here</a>.</p>
		<p>Audio file format support depends on the host, but the following table can be used as a reference.</p>
		<table class="table">
			<tr>
				<th>Format</th>
				<th>Chorme</th>
				<th>Firefox</th>
				<th>Edge</th>
				<th>Safari</th>
			</tr>
			<tr>
				<td>MP3</td>
				<td>Yes</td>
				<td>Yes</td>
				<td>Yes</td>
				<td>Yes</td>
			</tr>
			<tr>
				<td>FLAC</td>
				<td>No</td>
				<td>Yes</td>
				<td>No</td>
				<td>No</td>
			</tr>
			<tr>
				<td>OGG</td>
				<td>Yes</td>
				<td>Yes</td>
				<td>Yes</td>
				<td>No</td>
			</tr>
			<tr>
				<td>WAV</td>
				<td>Yes</td>
				<td>Yes</td>
				<td>Yes</td>
				<td>Yes</td>
			</tr>
			<tr>
				<td>WMA</td>
				<td>No</td>
				<td>No</td>
				<td>No</td>
				<td>No</td>
			</tr>
		</table>

		<h3>Load Audio Files</h3>
		<p>Its possible to load Audio files by selecting the import options in the asset explorer or by dragging audio files into the asset explorer directly.</p>

		<h3>Creating a audio emitter</h3>
		<p>To create a new audio emitter simply select the desired type of emitter from the toolbar, or drag the audio file to the scene editor, this will create a normal audio emitter by default.</p>
		<p>There are 2 types of audio emitters in nunuStudio, normal emitters that play 2D stereo audio, and positional audio emitters that simulate positional audio relative to the camera position to create a 3D audio effect.</p>

		<img src="assets/learn/basics/audio/select.jpg" style="width:20%; margin-left:40%"/>

		<h3>Controlling a audio emitter</h3>
		<p>Its possible to control a audio emitter using a script, the example bellow gets the audio emitter object, plays it on initialization and after 5 starts lowering its volume, after 10 seconds plays the audio again.</p>
		<pre><code class="hljs javascript">var audio;
var time, clock;

function initialize()
{{'{'}}
audio = scene.getObjectByName("test");

clock = new Clock();
clock.start();

time = 0;
{{'}'}}

function update()
{{'{'}}
time += clock.getDelta();

if(time > 5)
{{'{'}}
	audio.setVolume(audio.volume - 0.01);
{{'}'}}
if(audio.volume < 0.1)
{{'{'}}
	audio.pause();
{{'}'}}

if(time > 10)
{{'{'}}
	audio.setVolume(1.0);
	audio.play();
{{'}'}}
{{'}'}}</code></pre>

		<p>The example bellow shows how to control a positional audio object. When the mouse left button is pressed the sound starts playing, and when it is pressed again it stops. To try this example in the editor you can download the <a class="underline" href="audio.nsp">project file</a> or open it on the <a class="underline" href="https://www.nunustudio.org/editor?isp=https://nunustudio.org/learn/basics/06_audio/audio.nsp">Web Editor</a>.</p>

		<app-viewer fname="assets/learn/basics/audio/audio.nsp"></app-viewer>
	</div>
</div>
